namespace SeataNet.Core.Transaction
{
    /// <summary>
    /// 资源接口
    /// </summary>
    public interface IResource
    {
        /// <summary>
        /// 资源ID
        /// </summary>
        string ResourceId { get; }
        
        /// <summary>
        /// 资源组ID
        /// </summary>
        string ResourceGroupId { get; }
        
        /// <summary>
        /// 资源类型
        /// </summary>
        string ResourceType { get; }
        
        /// <summary>
        /// 提交分支事务
        /// </summary>
        /// <param name="xid">全局事务ID</param>
        /// <param name="branchId">分支事务ID</param>
        /// <param name="applicationData">应用数据</param>
        /// <returns>提交结果</returns>
        Task<bool> CommitAsync(string xid, long branchId, string? applicationData = null);
        
        /// <summary>
        /// 回滚分支事务
        /// </summary>
        /// <param name="xid">全局事务ID</param>
        /// <param name="branchId">分支事务ID</param>
        /// <param name="applicationData">应用数据</param>
        /// <returns>回滚结果</returns>
        Task<bool> RollbackAsync(string xid, long branchId, string? applicationData = null);
        
        /// <summary>
        /// 获取分支事务状态
        /// </summary>
        /// <param name="xid">全局事务ID</param>
        /// <param name="branchId">分支事务ID</param>
        /// <returns>分支事务状态</returns>
        Task<int> GetBranchStatusAsync(string xid, long branchId);
    }
}